# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gdbm
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.18.1
pkgrel=2
pkgdesc="GNU database library (mingw-w64)"
arch=('any')
url="https://www.gnu.org/software/gdbm/gdbm.html"
license=('GPL3')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-libiconv")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs')
source=(https://ftp.gnu.org/gnu/gdbm/${_realname}-${pkgver}.tar.gz{,.sig}
        'gdbm-1.15-win32.patch')
sha256sums=('86e613527e5dba544e73208f42b78b7c022d4fa5a6d5498bf18c8d6f745b91dc'
            'SKIP'
            'f6398a1a00839bed53565b6fae857a94ee6d12aaccd2a1e87b35203994a6ecd0')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -Np1 -i ${srcdir}/gdbm-1.15-win32.patch

  autoreconf --install --force
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --enable-shared \
    --enable-libgdbm-compat

  make
}

check() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make check || true
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
